Dart BigInt operator +
Syntax & Examples
BigInt.operator + operator
The `+` operator adds this BigInt to another BigInt.
Syntax of BigInt.operator +
The syntax of BigInt.operator + operator is:
operator +(BigInt other) → BigIntThis operator + operator of BigInt addition operator.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | the BigInt to be added |
✐ Examples
1 Add two positive BigInts
In this example,
- We define two positive BigInts,
num1with a value of10andnum2with a value of20. - We use the `+` operator to add them.
- We print the sum to standard output.
Dart Program
void main() {
BigInt num1 = BigInt.from(10);
BigInt num2 = BigInt.from(20);
BigInt sum = num1 + num2;
print('Sum: $sum');
}Output
Sum: 30
2 Add a negative and a positive BigInt
In this example,
- We define a negative BigInt
num1with a value of-10and a positive BigIntnum2with a value of20. - We use the `+` operator to add them.
- We print the sum to standard output.
Dart Program
void main() {
BigInt num1 = BigInt.from(-10);
BigInt num2 = BigInt.from(20);
BigInt sum = num1 + num2;
print('Sum: $sum');
}Output
Sum: 10
3 Add a positive and a negative BigInt
In this example,
- We define a positive BigInt
num1with a value of10and a negative BigIntnum2with a value of-20. - We use the `+` operator to add them.
- We print the sum to standard output.
Dart Program
void main() {
BigInt num1 = BigInt.from(10);
BigInt num2 = BigInt.from(-20);
BigInt sum = num1 + num2;
print('Sum: $sum');
}Output
Sum: -10
Summary
In this Dart tutorial, we learned about operator + operator of BigInt: the syntax and few working examples with output and detailed explanation for each example.